﻿using System;
using NUnit.Framework;
using NumSkull;

namespace NumSkullTests
{
    [TestFixture]
    [Category("Unit")]
    public class BoundsTests
    {
        [Test]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ConstructorValidatesRange()
        {
            new Bounds(5, 4);
        }

        [Test]
        public void ValidatesOutOfRangeLow()
        {
            var bounds = new Bounds(0, 10);

            Assert.That(bounds.IsInRange(-.0000001), Is.False);
        }

        [Test]
        public void ValidatesOutOfRangeHigh()
        {
            var bounds = new Bounds(0, 10);

            Assert.That(bounds.IsInRange(10.000001), Is.False);
        }

        [Test]
        public void ValidatesLowerRange()
        {
            var bounds = new Bounds(0, 10);

            Assert.That(bounds.IsInRange(0), Is.True);
        }

        [Test]
        public void ValidatesUpperRange()
        {
            var bounds = new Bounds(0, 10);

            Assert.That(bounds.IsInRange(10), Is.True);
        }

        [Test]
        public void ProducesRange()
        {
            var bounds = new Bounds(0, 10);

            Assert.That(bounds.Range, Is.EqualTo(10));
        }

        [Test]
        public void IsEqual()
        {
            var a = new Bounds(0, 10);
            var b = new Bounds(0, 10);

            Assert.That(a.Equals(b), Is.True);
        }

        [Test]
        public void IsObjectEqual()
        {
            var a = new Bounds(0, 10);
            var b = new Bounds(0, 10);

            Assert.That(a.Equals((object)b), Is.True);
        }

        [Test]
        public void IsHashCodeEqual()
        {
            var a = new Bounds(0, 10);
            var b = new Bounds(0, 10);

            Assert.That(a.GetHashCode().Equals(b.GetHashCode()), Is.True);
        }

        [Test]
        public void IsNotEqualLower()
        {
            var a = new Bounds(1, 10);
            var b = new Bounds(0, 10);

            Assert.That(a.Equals(b), Is.False);
        }

        [Test]
        public void IsNotEqualUpper()
        {
            var a = new Bounds(0, 9);
            var b = new Bounds(0, 10);

            Assert.That(a.Equals(b), Is.False);
        }

        [Test]
        public void IsNotEqualHashCode()
        {
            var a = new Bounds(0, 9);
            var b = new Bounds(0, 10);

            Assert.That(a.GetHashCode().Equals(b.GetHashCode()), Is.False);
        }

        [Test]
        public void ConstructsEmptyBounds()
        {
            var bounds = new Bounds(0, 0);

            Assert.That(bounds, Is.EqualTo(Bounds.Empty));
        }

        [Test]
        public void IsReferenceEqual()
        {
            var b = new Bounds(0, 0);

            var isEqual = b.Equals(b);

            Assert.That(isEqual, Is.True);
        }

        [Test]
        public void IsNullEqual()
        {
            var b = new Bounds(0, 0);

            var isEqual = b.Equals(null);

            Assert.That(isEqual, Is.False);
        }
    }
}
